package main

import (
	"fmt"
	"math/rand"
	"time"
)

var intChan chan int

func main() {
  intChan:=make(chan int,50)
  exitChan:=make(chan bool,1)
  go writeData(intChan)
  go readData(intChan,exitChan)
  if <-exitChan{
	  return
  }
	fmt.Println("main end")
}

func writeData(intChan chan int) {
	rand.Seed(time.Now().UnixNano())
	for i := 1; i < 50; i++ {
		var tempInt int
		tempInt = rand.Intn(4) + 10
		intChan <- tempInt
	}
	close(intChan)
}

func readData(intChan chan int,exitChan chan bool)  {
	var count int
	for{
		val,ok:=<-intChan
		count++
		if !ok{
			break
		}
		fmt.Printf("read value is: %v,count is %v \n",val,count)

	}
	exitChan<-true
	close(exitChan)
}
